var _timer = 30000;
var _split = 1;
var _id = 0;
var _status = "资料读取中...";

var g_numcolor = [0,1,1,2,2,3,3,1,1,2,2,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,1,2,3,3,1,1,2,2,3,3,1,2,2,3,3,1,1,2,2,3];
var colors = ["","red", "blue", "green"];
var mchk13 = [0,0,0,0];
var mchk14 = [0,0,0,0,0,0,0,0,0,0,0,0,0];
var mchk18 = [0,0,0,0,0,0,0,0,0,0,0,0];
var XH = null;
var XH1= null;
if (window.XMLHttpRequest)
{// code for all new browsers
    XH = new XMLHttpRequest();
    XH1 = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
  XH = new ActiveXObject("Microsoft.XMLHTTP");
  XH1 = new ActiveXObject("Microsoft.XMLHTTP");
} else 
  alert("Your browser does not support XMLHTTP.");

var timer_id;
var chkbutmod = false;
var b133_num = "";
var b143_num = "";
var b183_num = "";
//   Math.round(n) = 去小数取整数，Math.floor(n) = 四舍五入到整数

function getcontent()
{
    XH.open("POST", "op.php?op=xml&fp=bnow12&id="+_id+"&split="+_split,false); 
    try{XH.send("");return XH.responseText; }catch(E){}
}

function timer()
{
	window.status = _status;
	var i;
	var str = getcontent();
	if (str=="") { alert("Error 1"); }
	if (str=="-1") { location.reload(); }

	var a = str.split("\n");
	show_rate13(a[0]);
	show_rate14(a[1]);
	show_rate18(a[2]);
	show_titleAmu(a[3]);
	window.status = "";

	// timer_id = setTimeout("timer()", _timer);
}

function show_rate13(str)
{
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<4; i++) {
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		chktime = a00[4]-0;
		document.all["rate13_"+i].innerHTML = rate;
		mchk13[i] = Math.floor(amount);
		if (count > 0) {
			document.all["amount13_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype=13&numbers="+i+">"+Math.floor(amount)+"</a>";
			if (chktime == 0 && amount > 0) {
				document.all["chg13_"+i].innerHTML = "<input type=checkbox id=rrr13_"+d2(i)+" onclick=\"quickrrr(13, "+i+")\">";
			} else {
				document.all["chg13_"+i].innerHTML = "<input disabled type=checkbox id=rrr13_"+d2(i)+">";
			}
		} else {
			document.all["amount13_"+i].innerHTML = Math.floor(amount);
			document.all["chg13_"+i].innerHTML = "<input disabled type=checkbox id=rrr13_"+d2(i)+">";
		}
		win1 = Math.floor(win - a00[3]);
		document.all["win13_"+i].innerHTML = win1;
		document.all["win13_"+i].className = (win1 < 0 ? "lost" : "win");
	}
}

function show_rate14(str)
{
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<13; i++) {
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		chktime = a00[4]-0;
		document.all["num14_"+i].innerHTML = _name14[i];
		document.all["rate14_"+i].innerHTML = rate;
		mchk14[i] = Math.floor(amount);
		if (count > 0) {
			document.all["amount14_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype=14&numbers="+i+">"+Math.floor(amount)+"</a>";
			if (chktime == 0 && amount > 0) {
				document.all["chg14_"+i].innerHTML = "<input type=checkbox id=rrr14_"+d2(i)+" onclick=\"quickrrr(14, "+i+")\">";
			} else {
				document.all["chg14_"+i].innerHTML = "<input disabled type=checkbox id=rrr14_"+d2(i)+">";
			}
		} else {
			document.all["amount14_"+i].innerHTML = Math.floor(amount);
			document.all["chg14_"+i].innerHTML = "<input disabled type=checkbox id=rrr14_"+d2(i)+">";
		}
		win1 = Math.floor(win - a00[3]);
		document.all["win14_"+i].innerHTML = win1;
		document.all["win14_"+i].className = (win1 < 0 ? "lost" : "win");
	}
}


function show_rate18(str)
{
	var a0 = str.split(",");
	var win = a0[0];
	for (i=1; i<13; i++) {
		a00 = a0[i].split("@");
		rate = a00[0];
		count = a00[1]-0;
		amount = a00[2]-0;
		chktime = a00[4]-0;
		document.all["num18_"+i].innerHTML = _name18[i];
		document.all["rate18_"+i].innerHTML = rate;
		mchk18[i] = Math.floor(amount);
		if (count > 0) {
			document.all["amount18_"+i].innerHTML = "<a href=op.php?op=agent&fp=betlist&dt1="+_open+"&dt2="+_open+"&bettype=18&numbers="+i+">"+Math.floor(amount)+"</a>";
			if (chktime == 0 && amount > 0) {
				document.all["chg18_"+i].innerHTML = "<input type=checkbox id=rrr18_"+d2(i)+" onclick=\"quickrrr(18, "+i+")\">";
			} else {
				document.all["chg18_"+i].innerHTML = "<input disabled type=checkbox id=rrr18_"+d2(i)+">";
			}
		} else {
			document.all["amount18_"+i].innerHTML = Math.floor(amount);
			document.all["chg18_"+i].innerHTML = "<input disabled type=checkbox id=rrr18_"+d2(i)+">";
		}
		win1 = Math.floor(win - a00[3]);
		document.all["win18_"+i].innerHTML = win1;
		document.all["win18_"+i].className = (win1 < 0 ? "lost" : "win");
	}
}
function show_titleAmu(str)
{
	var a0 = str.split(",");
	var i = 0;
	var l = a0.length;
	var amu = 0;
	var clr = '';
	var oObj = '';
	for (i=0; i<l; i++) {
		a00 = a0[i].split("@");
		amu = a00[0];
		if(a00[1] > 0){ clr = '#ffff99';  }else{ clr = 'transparent';  }
    oObj = document.getElementById("menuAmu"+i);
    oObj.innerHTML = amu;
    oObj.style.backgroundColor = clr;
	}
}
function quickrrr(c, i)
{
	if (document.all["rrr"+c+"_"+d2(i)].checked) {
		if (!chkbutmod) {
			chkbutmod = true;
		}
		if (timer_id) clearTimeout(timer_id);
		// timer_id = setTimeout("timer()", 90000);
	}
}

function gen_rate13()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>"+_tb13head+"</tr>";
	ret += "<tr class=td2 align=right><td class=td15 align=center><font color=red>"+_name13[1]+"</font></td><td nowrap id=amount13_1></td><td nowrap id=win13_1></td><td id=rate13_1 class=rate></td><td align=center id=chg13_1></td></tr>";
	ret += "<tr class=td2 align=right><td class=td15 align=center><font color=blue>"+_name13[2]+"</font></td><td nowrap id=amount13_2></td><td nowrap id=win13_2></td><td id=rate13_2 class=rate></td><td align=center id=chg13_2></td></tr>";
	ret += "<tr class=td2 align=right><td class=td15 align=center><font color=green>"+_name13[3]+"</font></td><td nowrap id=amount13_3></td><td nowrap id=win13_3></td><td id=rate13_3 class=rate></td><td align=center id=chg13_3></td></tr>";
	ret += "</table>";
	document.all.div13.innerHTML = ret;
}

function gen_rate14()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>";
	for (i=0; i<4; i++) ret += _tb14head;
	ret += "</tr>";
	
	for (j=0; j<3; j++) {
		ret += "<tr class=td2 align=right>";
		for (i=1; i<5; i++) {
			k = i + j*4;
			ret += "<td id=num14_"+k+" class=td15 align=center></td><td nowrap id=amount14_"+k+"></td><td nowrap id=win14_"+k+"></td><td id=rate14_"+k+" class=rate></td><td align=center id=chg14_"+k+"></td>";
		}
	}
	ret += "</table>";
	document.all.div14.innerHTML = ret;
}


function gen_rate18()
{
	ret = "<table width=100% cellpadding=2 cellspacing=1 border=0 class=table0>"
		+"<tr id=rate0hd class=td0 align=center>";
	for (i=0; i<2; i++) ret += _tb18head;
	ret += "</tr>";
	
	for (j=0; j<6; j++) {
		ret += "<tr class=td2 align=right>";
		for (i=1; i<3; i++) {
			k = i + j*2;
			ret += "<td id=num18_"+k+" class=td15 align=center></td><td nowrap id=amount18_"+k+"></td><td nowrap id=win18_"+k+"></td><td id=rate18_"+k+" class=rate></td><td align=center id=chg18_"+k+"></td>";
		}
	}
	ret += "</table>";
	document.all.div18.innerHTML = ret;
}

function protect_b1()
{
	var bw = 262;
	var sr = 0;
	var hi =104;
	var count = 0;
	var _bet = new Array();
	var _num = new Array();
	var _chk = new Array();
	var _rate = new Array();
	var _amount = new Array();
	b133_num = document.all.b133.value-0;
	if (b133_num > 0) {
		for (i=1; i<4; i++) {
			if (document.all["rrr13_"+d2(i)].checked) {
				_bet[count] = 13;
				_num[count] = i;
				_rate[count] = document.all["rate13_"+i].innerHTML;
				_chk[count] = mchk13[i];
				_amount[count] = b133_num;
				count++;
			}
		}
		if (count > 0) {
			hi += (count * 26);
			if (count > 24) {
				sr = 1;
				bw = 280;
				hi = 794;
			}
			var X = screen.width - bw - 10;
			var Y = 0;
			//var newwin = window.open("op.php?op=agent&fp=protsaves&btype="+_bet+"&num="+_num+"&rate="+_rate+"&amount="+_amount+"&chk="+_chk,'WinProtPop','menubar=no,status=yes,scrollbars='+sr+',toolbar=no,top='+Y+',left='+X+',width='+bw+',height='+hi);
			var newwin = myCreateDiv("op.php?op=agent&fp=protsaves&btype="+_bet+"&num="+_num+"&rate="+_rate+"&amount="+_amount+"&chk="+_chk);
			//setTimeout("isPopOpen(newwin)",1500);
		}
	}
	b133_num = "";
	document.all.b133.value = b133_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function protect_b2()
{
	var bw = 262;
	var sr = 0;
	var hi =104;
	var count = 0;
	var _bet = new Array();
	var _num = new Array();
	var _chk = new Array();
	var _rate = new Array();
	var _amount = new Array();
	b143_num = document.all.b143.value-0;
	if (b143_num > 0) {
		for (i=1; i<13; i++) {
			if (document.all["rrr14_"+d2(i)].checked) {
				_bet[count] = 14;
				_num[count] = i;
				_rate[count] = document.all["rate14_"+i].innerHTML;
				_chk[count] = mchk14[i];
				_amount[count] = b143_num;
				count++;
			}
		}
		if (count > 0) {
			hi += (count * 26);
			if (count > 24) {
				sr = 1;
				bw = 280;
				hi = 794;
			}
			var X = screen.width - bw - 10;
			var Y = 0;
			// var newwin = window.open("op.php?op=agent&fp=protsaves&btype="+_bet+"&num="+_num+"&rate="+_rate+"&amount="+_amount+"&chk="+_chk,'WinProtPop','menubar=no,status=yes,scrollbars='+sr+',toolbar=no,top='+Y+',left='+X+',width='+bw+',height='+hi);
			var newwin = myCreateDiv("op.php?op=agent&fp=protsaves&btype="+_bet+"&num="+_num+"&rate="+_rate+"&amount="+_amount+"&chk="+_chk);
			//setTimeout("isPopOpen(newwin)",1500);
		}
	}
	b143_num = "";
	document.all.b143.value = b143_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function protect_b3()
{
	var bw = 262;
	var sr = 0;
	var hi =104;
	var count = 0;
	var _bet = new Array();
	var _num = new Array();
	var _chk = new Array();
	var _rate = new Array();
	var _amount = new Array();
	b183_num = document.all.b183.value-0;
	if (b183_num > 0) {
		for (i=1; i<13; i++) {
			if (document.all["rrr18_"+d2(i)].checked) {
				_bet[count] = 18;
				_num[count] = i;
				_rate[count] = document.all["rate18_"+i].innerHTML;
				_chk[count] = mchk18[i];
				_amount[count] = b183_num;
				count++;
			}
		}
		if (count > 0) {
			hi += (count * 26);
			if (count > 24) {
				sr = 1;
				bw = 280;
				hi = 794;
			}
			var X = screen.width - bw - 10;
			var Y = 0;
			// var newwin = window.open("op.php?op=agent&fp=protsaves&btype="+_bet+"&num="+_num+"&rate="+_rate+"&amount="+_amount+"&chk="+_chk,'WinProtPop','menubar=no,status=yes,scrollbars='+sr+',toolbar=no,top='+Y+',left='+X+',width='+bw+',height='+hi);
			var newwin = myCreateDiv("op.php?op=agent&fp=protsaves&btype="+_bet+"&num="+_num+"&rate="+_rate+"&amount="+_amount+"&chk="+_chk);
			//setTimeout("isPopOpen(newwin)",1500);
		}
	}
	b183_num = "";
	document.all.b183.value = b183_num;
	if (chkbutmod) {
		chkbutmod = false;
		timer();
	}
}

function prot_list()
{
	var X = (screen.width-470)/2;
	var Y = (screen.Height-424)/2;
	// var newwin = window.open("op.php?op=agent&fp=protlists&bmd=2",'WinPopList','menubar=no,status=yes,scrollbars=no,toolbar=no,top='+Y+',left='+X+',width=540,height=412');
	var newwin = myCreateDiv("op.php?op=agent&fp=protlists&bmd=2");
	//setTimeout("isPopOpen(newwin)",1500);
}

function myCreateDiv(sSrc){
    var shadow = document.createElement("div");
    shadow.setAttribute("id","speShadow2");
    shadow.style.zIndex="100";

    var box = document.createElement("div");
    box.setAttribute("id","speBox2");
    box.style.zIndex="999";
    
    var closeBar = document.createElement("div");
    closeBar.setAttribute("id","closeBar");
    
    var iptClose = document.createElement("input");
    iptClose.setAttribute("type","button");
    iptClose.setAttribute("value"," X ");
    iptClose.setAttribute("className","c4");
    iptClose.onclick = function() {myCloseMyDiv(0);};
    
    closeBar.appendChild(iptClose);
    box.appendChild(closeBar);
    
    var myIframe = document.createElement("iframe");
    myIframe.setAttribute("id","myIfram_target");
    myIframe.setAttribute("name","myIfram_target");
    myIframe.style.width = "100%";
    myIframe.style.height = "100%";
    myIframe.src = sSrc;
    box.appendChild(myIframe);
    
    document.body.appendChild(shadow);
    document.body.appendChild(box);    
};

function myCloseMyDiv(oReload){
    var shadow=document.getElementById("speShadow2");
    if(shadow != undefined){
      var box=document.getElementById("speBox2");
      document.body.removeChild(box);
      document.body.removeChild(shadow);
      if(oReload) window.location.reload();
    }
}

function w(s) {
	document.write(s);
}

function winonload()
{
	gen_rate13();
	gen_rate14();
	gen_rate18();
	b133_num = document.all.b133.value-0;

	b143_num = document.all.b143.value-0;
	chkbutmod = false;
	timer();
}

window.onload = winonload;